home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / CLOCK.AML < prev    next >
Text File  |  1996-07-17  |  4KB  |  148 lines

  1. //--------------------------------------------------------------------
  2. // CLOCK.AML
  3. // Digital Clock, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Clock.dox for user help)
  6. //
  7. // This macro displays a digital clock window, using large digits for
  8. // the current time. The current date is also displayed in full format
  9. // obtained from calling Cfg\Cfgintnl.x.
  10. //
  11. // The time and date are updated continuously. The clock window is
  12. // modeless, allowing you to switch windows while the clock is running.
  13. //
  14. // Usage:
  15. //
  16. // Select this macro from the Macro List (on the Macro menu), or run it
  17. // from the macro picklist <shift f12>.
  18. //--------------------------------------------------------------------
  19.  
  20. include bootpath "define.aml"
  21.  
  22. // clock colors
  23. constant clock_digit_color      = color brightred   on black
  24. constant clock_separator_color  = color green       on black
  25. constant clock_ampm_color       = color green       on black
  26. constant clock_date_color       = color green       on darkgray
  27.  
  28. constant clock_separator_char   = '.'
  29. constant clock_digit_width      = 4
  30.  
  31. // clock timer
  32. constant clock_timer_delay  = 1000
  33.  
  34. variable clockwin, timerid
  35.  
  36. // keep this macro resident
  37. resident ON
  38. settype "win"
  39.  
  40. // large digits
  41. digits = {
  42.   " __      __  __      __  __  __  __  __     "
  43.   "|  |  |  __| __||__||__ |__    ||__||__|    "
  44.   "|__|  | |__  __|   | __||__|   ||__|   |    "
  45. }
  46.  
  47. variable datestr, lasttime
  48.  
  49. // write a large digit string at x,y
  50. private function writedigits (digitstr x y)
  51.   for j = 1 to length digitstr do
  52.     k = digitstr [j]
  53.     if k == ' ' then
  54.       k = 10
  55.     end
  56.     k = (k * clock_digit_width) + 1
  57.     for i = 1 to length digits do
  58.       writestr digits [i][k : 4] clock_digit_color x y + i - 1
  59.     end
  60.     x = x + clock_digit_width
  61.   end
  62. end
  63.  
  64.  
  65. // called every second to update the date and time
  66. function tick
  67.   oldwindow = gotowindow clockwin
  68.  
  69.   // format: YYYYMMDDWhhmmssuu
  70.   time = getrawtime
  71.  
  72.   hours = time [10:2]
  73.  
  74.   // hours have changed
  75.   if hours <> lasttime [10:2] then
  76.     itime = gettime
  77.     if itime [1] == '0' then
  78.       itime [1] = ' '
  79.     end
  80.     // date has changed
  81.     if not lasttime or hours == 0 then
  82.       datestr = runmacro (bootpath "cfg\\cfgintnl.x") '' 'f'
  83.       writestr (datestr + ' ') : 35  clock_date_color 4 6
  84.     end
  85.     // am/pm/24hr indicator
  86.     writestr (if? itime [LAST_CHAR] <> 'm' '24'
  87.                (if? hours >= 12 'PM' 'AM')) clock_ampm_color 36 4
  88.     // write hours in international format
  89.     writedigits (itime [1..2]) 5 2
  90.   end
  91.  
  92.   // minutes
  93.   if time [12:2] <> lasttime [12:2] then
  94.     writedigits time [12:2] 16 2
  95.   end
  96.  
  97.   // seconds
  98.   writedigits time [14:2] 27 2
  99.  
  100.   lasttime = time
  101.  
  102.   gotowindow oldwindow
  103. end
  104.  
  105. // initial clock display
  106. private function firsttick
  107.   // clock background
  108.   oldwindow = gotowindow clockwin
  109.   hilite 35 4 clock_digit_color 4 2
  110.   writestr clock_separator_char clock_ampm_color 14 3
  111.   writestr clock_separator_char clock_ampm_color 14 4
  112.   writestr clock_separator_char clock_ampm_color 25 3
  113.   writestr clock_separator_char clock_ampm_color 25 4
  114.   gotowindow oldwindow
  115.   tick
  116. end
  117.  
  118. event <destroy>
  119.   destroytimer timerid
  120. end
  121.  
  122. // display the clock dialog box
  123. private function clockdlg (zero)
  124.   clockwin = dialog "Clock" 41 7 "c" (getcurrobj)
  125.   // start the clock timer
  126.   // (generate a unique timerid since there may be multiple instances)
  127.   timerid = setrepeat '' clock_timer_delay (getcurrobj) "tick"
  128.   firsttick
  129.   showdialog
  130. end
  131.  
  132. // called by Lib.x when the dialog box is closed
  133. function onclosedlg
  134.   destroyobject
  135. end
  136.  
  137. macrofile = arg 1
  138.  
  139. // called by Lib.x when a key is entered in the dialog box
  140. function ondialog (keycode)
  141.   // macro help
  142.   if keycode == <f1> then
  143.     helpmacro macrofile
  144.   end
  145. end
  146.  
  147. clockdlg
  148.